<template>
  <div class="tab-control">
    <div class="tab-conterol-item" 
         v-for="(item , index) in titles" :key="item.index"
         :class="{active: index === currentIndex}"
         @click="itemClick(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentIndex:0
    }
  },
  props:{
    titles:{
      type:Array,
      default(){
        return []
      }
    }
  },
  methods:{
    itemClick(index){
      this.currentIndex = index;
      // tabClick事件名  index传递的参数
      this.$emit('tabClick',index)
    }
  }
}
</script>
<style lang='less' scoped>
      .tab-control {
        
        height:40px;
        line-height:40px;
        text-align: center;
        font-size:14px;
        background-color:#ffffff;
        width: 100%;
        z-index: 30;
        position: sticky;
        top:44px;
        display:flex;
        .tab-conterol-item {
            flex:1;
            span {
                padding:6px;
            }
        }
        .active {
            color:var(--color-tint);
            span {
                border-bottom:3px solid var(--color-tint);
            }
        }
    }
</style>
